package com.ruoyi.web.controller.assets;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ScrapLog;
import com.ruoyi.system.service.IScrapLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报废日志Controller
 * 
 * @author hzl
 * @date 2025-03-25
 */
@RestController
@RequestMapping("/assets/scrapLog")
public class ScrapLogController extends BaseController
{
    @Autowired
    private IScrapLogService scrapLogService;

    /**
     * 查询报废日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:list')")
    @GetMapping("/list")
    public TableDataInfo list(ScrapLog scrapLog)
    {
        startPage();
        List<ScrapLog> list = scrapLogService.selectScrapLogList(scrapLog);
        return getDataTable(list);
    }

    /**
     * 导出报废日志列表
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:export')")
    @Log(title = "报废日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScrapLog scrapLog)
    {
        List<ScrapLog> list = scrapLogService.selectScrapLogList(scrapLog);
        ExcelUtil<ScrapLog> util = new ExcelUtil<ScrapLog>(ScrapLog.class);
        util.exportExcel(response, list, "报废日志数据");
    }

    /**
     * 获取报废日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return success(scrapLogService.selectScrapLogByLogId(logId));
    }

    /**
     * 新增报废日志
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:add')")
    @Log(title = "报废日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScrapLog scrapLog)
    {
        return toAjax(scrapLogService.insertScrapLog(scrapLog));
    }

    /**
     * 修改报废日志
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:edit')")
    @Log(title = "报废日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScrapLog scrapLog)
    {
        return toAjax(scrapLogService.updateScrapLog(scrapLog));
    }

    /**
     * 删除报废日志
     */
    @PreAuthorize("@ss.hasPermi('assets:scrapLog:remove')")
    @Log(title = "报废日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(scrapLogService.deleteScrapLogByLogIds(logIds));
    }
}
